﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLTVNEW
{
    public partial class frmLocSanhTra : DevComponents.DotNetBar.Office2007Form
    {
        public frmLocSanhTra()
        {
            InitializeComponent();
        }
        QLTVDataContext db = new QLTVDataContext();
        #region 'LT'
        void LoadGridView(DataGridView gv)
        {
            var query = from tphieu in db.PHIEUMUONTRASACHes
                        join tbdg in db.DOCGIAs on tphieu.MaDocGia equals tbdg.MaDocGia
                        join tbsach in db.SACHes on tphieu.MaSach equals tbsach.MaSach
                        where tphieu.LoaiMuonTra == "Trả"
                        select new
                        {
                            tbsach.TenSach,
                            tbsach.THELOAI.TenTheLoai,
                            tbsach.MaSach,
                            tbdg.MaDocGia,
                            tbdg.HoTen,
                            tphieu.NgayMuonSach,
                            tphieu.NgayTraSach,
                            tphieu.TienPhat

                        };
            gv.DataSource = query;
        }
        #endregion
        private void frmLocSanhTra_Load(object sender, EventArgs e)
        {
            LoadGridView(GVW);
            txtTS.Text = GVW.Rows[0].Cells[0].Value.ToString().Trim();
            txtTheLoai.Text = GVW.Rows[0].Cells[1].Value.ToString().Trim();
            txtMaSach.Text = GVW.Rows[0].Cells[2].Value.ToString().Trim();
            txtMaDG.Text = GVW.Rows[0].Cells[3].Value.ToString().Trim();
            txtTen.Text = GVW.Rows[0].Cells[4].Value.ToString().Trim();
            mktMuonSach.Text = GVW.Rows[0].Cells[5].Value.ToString().Trim();
            mktTraSach.Text = GVW.Rows[0].Cells[6].Value.ToString().Trim();
            txtTienPhat.Text = String.Format("{0:#,##0 VND}", GVW.Rows[dong].Cells[7].Value);
        }

        int dong;
        private void GVW_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                dong = e.RowIndex;
                txtTS.Text = GVW.Rows[dong].Cells[0].Value.ToString().Trim();
                txtTheLoai.Text = GVW.Rows[dong].Cells[1].Value.ToString().Trim();
                txtMaSach.Text = GVW.Rows[dong].Cells[2].Value.ToString().Trim();
                txtMaDG.Text = GVW.Rows[dong].Cells[3].Value.ToString().Trim();
                txtTen.Text = GVW.Rows[dong].Cells[4].Value.ToString().Trim();
                mktMuonSach.Text = GVW.Rows[dong].Cells[5].Value.ToString().Trim();
                mktTraSach.Text= GVW.Rows[dong].Cells[6].Value.ToString().Trim();
                txtTienPhat.Text = String.Format("{0:#,##0 VND}", GVW.Rows[dong].Cells[7].Value);
            }
            catch
            {
                return;
            }

        }

        private void txtTen_TextChanged(object sender, EventArgs e)
        {

        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
